package com.atzly.community.datasource;

import lombok.ToString;

import java.io.Serializable;
import java.net.URI;

/**
 * 数据源配置
 */
@ToString
public class DataSourceConfig implements Serializable {
	private static final long serialVersionUID = -3211436249152148183L;
	private static String MASK = "***";
	private String url;
	private String username;
	private String password;
	private Integer initialSize;
	private Integer maxActive;
	private Integer minIdle;
	private String driverClassName;

	private String dbId;

	public String getDbId() {
		return dbId;
	}

	public void setDbId(String dbId) {
		this.dbId = dbId;
	}

	public String getDriverClassName() {
		return driverClassName;
	}

	public void setDriverClassName(String driverClassName) {
		this.driverClassName = driverClassName;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getInitialSize() {
		return initialSize;
	}

	public void setInitialSize(Integer initialSize) {
		this.initialSize = initialSize;
	}

	public Integer getMaxActive() {
		return maxActive;
	}

	public void setMaxActive(Integer maxActive) {
		this.maxActive = maxActive;
	}

	public Integer getMinIdle() {
		return minIdle;
	}

	public void setMinIdle(Integer minIdle) {
		this.minIdle = minIdle;
	}
	
	/**
	 * 获取Db信息
	 * @return
	 */
	public String getDbInfo() {
		URI dbUri = URI.create(url.startsWith("jdbc:") ? url.substring(5) : url);
		
		return String.format("%s@%s:%d%s", username,
				dbUri.getHost(), dbUri.getPort(), dbUri.getPath());
	}





}
